package db.tables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.db.Table;

import db.beans.T_ResearchResultBean;

public class T_ResearchResultTable extends Table{

	public static final String COL_SRC_PRODUCT_ID = "SRC_PRODUCT_ID";
	public static final String COL_DES_PRODUCT_ID = "DES_PRODUCT_ID";
	public static final String COL_DIFFERENCE_PRICE = "DIFFERENCE_PRICE";
	public static final String COL_STATUS = "STATUS";

	public static void insert(Connection conn, String strTableName, T_ResearchResultBean[] arrResultData) throws SQLException{
		final String sql = "INSERT INTO " + strTableName
						+ "(" + COL_SRC_PRODUCT_ID
						+ "," + COL_DES_PRODUCT_ID
						+ "," + COL_DIFFERENCE_PRICE
						+ "," + COL_STATUS
						+ ") VALUES (?,?,?,?)";
		PreparedStatement stmt = null;
		try {
			stmt = conn.prepareStatement(sql);
			int index = 0;
			for (int i = 0; i < arrResultData.length; i++){
				stmt.setLong(++index, arrResultData[i].getSrcProductCode());
				stmt.setLong(++index, arrResultData[i].getDesProductCode());
				stmt.setDouble(++index, arrResultData[i].getDifferencePrice());
				stmt.setInt(++index, arrResultData[i].getStatus());
				stmt.addBatch();
			}

			stmt.executeBatch();
		} finally{
			if(stmt!=null) {
				stmt.close();
			}
			conn.commit();
		}
	}
}

